package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.AlbumStat;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album")
@SuppressWarnings({"all"})
public class AlbumInfoApiController {

	@Autowired
	private AlbumInfoService albumInfoService;
	@Autowired
	private BaseCategoryService baseCategoryService;

	@GuiGuLogin(required=true)
	@Operation(summary = "内容创作者或者平台运营人员-保存专辑")
     @PostMapping("/albumInfo/saveAlbumInfo")
	public Result saveAlbumInfo(@Validated @RequestBody AlbumInfoVo albumInfoVo){
		 Long userId = AuthContextHolder.getUserId();
		 albumInfoService.saveAlbumInfo(albumInfoVo,userId);
		 return Result.ok();
	 }

	 @GuiGuLogin(required = true)
	 @Operation(summary = "分页条件查询当前登录用户发布专辑")
	 @PostMapping("/albumInfo/findUserAlbumPage/{page}/{limit}")
	public Result<Page<AlbumListVo>> findUserAlbumPage(@PathVariable Long page,
													   @PathVariable Long limit,
													   @RequestBody AlbumInfoQuery albumInfoQuery)
	 {
		 Long userId = AuthContextHolder.getUserId();
		 albumInfoQuery.setUserId(userId);
		 Page<AlbumListVo> pageParam=new Page<>(page,limit);
		 pageParam=albumInfoService.findUserAlbumPage(pageParam,albumInfoQuery);
		 return Result.ok(pageParam);
	 }

	 @Operation(summary = "删除专辑(包括标签关系,统计数值)")
	 @DeleteMapping("/albumInfo/removeAlbumInfo/{id}")
	public Result removeAlbumInfo(@PathVariable Long id){
		albumInfoService.removeAlbumInfo(id,true);
		return Result.ok();
	 }

	 @Operation(summary = "根据专辑ID查询专辑信息(包含专辑标签列表)")
	 @GetMapping("/albumInfo/getAlbumInfo/{id}")
	public Result<AlbumInfo> getAlbumInfo(@PathVariable Long id){
		AlbumInfo albumInfo=albumInfoService.getAlbumInfo(id);
		return Result.ok(albumInfo);
	 }


	 @Operation(summary = "更新专辑的信息")
	 @PutMapping("/albumInfo/updateAlbumInfo/{id}")
	public Result updateAlbumInfo(@PathVariable Long id,@Validated @RequestBody AlbumInfoVo albumInfoVo){
              albumInfoService.updateAlbumInfo(id,albumInfoVo);
			  return Result.ok();
	 }

	 @GuiGuLogin
@Operation(summary = "查询当前登录用户专辑列表")
	@GetMapping("/albumInfo/findUserAllAlbumList")
	public Result<List<AlbumInfo>> findUserAllAlbumList(){
		////1.获取当前用户登录ID
	Long userId = AuthContextHolder.getUserId();
	//调用业务层获取专辑列表
	List<AlbumInfo> list=albumInfoService.findUserAllAlbumList(userId);
		return Result.ok(list);
	}

@Operation(summary = "根据专辑ID查询专辑统计数值")
	@GetMapping("/albumInfo/getAlbumStatVo/{albumId}")
	public Result<AlbumStatVo> getAlbumStatVo(@PathVariable Long albumId){
		AlbumStatVo albumStatVo=albumInfoService.getAlbumStatVo(albumId);
		return Result.ok(albumStatVo);
	}


}

